package com.kfm.servlet;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;

@WebServlet("/response1")
public class ResponseServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        resp.setStatus(300);
//        resp.sendError(300, "kfm");
        // 设置响应输出流的字符编码
        resp.setCharacterEncoding("utf-8");
        resp.setStatus(300, "kfm");
        // 设置响应头 设置页面上的字符编码
        resp.setHeader("content-type", "image/jpeg");
        // 获取字符输出流 将内容输出到浏览器
//        PrintWriter writer = resp.getWriter();
        ServletOutputStream outputStream = resp.getOutputStream();
        FileInputStream in = new FileInputStream("G:\\Image\\开发喵\\logo.png");
        in.transferTo(outputStream);
        in.close();
        outputStream.flush();
        outputStream.close();
//        String html = "<h1>hello 张三</h1>";
//        writer.write(html);
    }
}
